	(ns cl-slika.views.welcome
	  (:require [cl-slika.views.common :as common]
	            [noir.session :as session]
	            [noir.response :as resp]
	            [clojure.java.io :as io]
	            [cl-slika.models.user :as users]
	            )
	  (:use [noir.core :only [defpage]]
	        [cl-slika.picture.pic]
         [cl-slika.views.sadrzaj]
	        )
	  )
	
(defpage "/logout" []
	  (users/logout)     
	   (resp/redirect "/?poruka=izlogovani ste") 
   )
     
  
(defpage "/" [& params]
	(let [
       poruka  (first params)
        poruka1 (get poruka 1)
        downPu (if (= (get poruka 0) :putanja) poruka1 "")
        por (if (= (get poruka 0) :poruka) poruka1 "")
        ]
 
	         (common/layout
	           [:div#wrapper  (str "<script> prikaziPoruku('" por "');</script>" )
		           [:div#idHeader (div-login) (div-register) (session-btns) ]
		           [:div#idLevo.levo.zaobljeno (forma) ]
		           [:div#idCentralni]
              (if (= downPu "") () (down downPu))
		          ]
	           )
          )
    )
	 
(defpage [:post "/upload1"] {:keys [myFile filter ]}
	 
	  (let [src (:tempfile myFile)
	        random (bigint (rand (* 10 1000)))
	        name (str random "-" (:filename myFile))
	        dest (str "./upload/" name )] ;;dodati random broj random ime fajla
		  (io/copy 
		    (io/file src)   
		    (io/file dest)
		   )
	   
		  (uzas name (Integer/parseInt filter) "10 10 10");"GreenFilter"
		 (resp/redirect (str "/?putanja=" name ))
	   
		 )
	 )
	
(defpage "/link" {:keys [putanja]}
	(let [extenzija (re-find #"\.\w{3}" putanja)]
	  {:status 200
	       :headers {"Content-Type" "image" ;format
	                 "Content-Disposition"  (str "attachment;filename=" (str "slika.jpg" ))     ;extenzija            
	                 }
	       
	       :body (io/file 
	              (str  "./upload/" "-o-" putanja );               
	              )
	      }
	 
	      )    
	  )

(defpage [:post "/user/add"] {:keys [username passwordR] :as new-user}
     (let [poruka (users/add! new-user)]     
       (autenticate poruka username)
       
   )
     )

(defpage [:post "/user/provera"] {:keys [username password] :as new-user}
        
  (let [poruka (users/login! new-user)]     
       (autenticate poruka username)
 ))
	
